<template xmlns="http://www.w3.org/1999/html">
  <div class="app-container">
    <el-form :model="formData" ref="elForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="userName">
        <el-input
          v-model="formData.userName"
          placeholder="请输入姓名"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phoneNumber">
        <el-input
          v-model="formData.phoneNumber"
          placeholder="请输入手机号"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="打卡类型" prop="clockType">
        <el-select v-model="formData.clockType" placeholder="请选择打卡类型" clearable>
          <el-option v-for="(item, index) in clocktypeOptions" :key="index" :label="item.label"
                     :value="item.value" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="打卡时间" prop="clockTime">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button type="info" icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['user:attendance:export']"
        >导出
        </el-button>
      </el-form-item>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-form>
    <br>

    <el-table v-loading="loading" :data="attendanceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center"/>
      <el-table-column label="序号" prop="attendanceId" align="center"/>
      <el-table-column label="所属运营商" align="center" prop="deptName"/>
      <el-table-column label="姓名" align="center" prop="userName"/>
      <el-table-column label="手机号" align="center" prop="phoneNumber"/>
      <el-table-column label="打卡类型" align="center" prop="clockType">
        <template slot-scope="scope">
          <div v-if="scope.row.clockType === '0' ">
            上班打卡
          </div>
          <div v-else>
            下班打卡
          </div>
        </template>
      </el-table-column>
      <el-table-column label="打卡路段" align="center" prop="clockRoad"/>
      <el-table-column label="打卡时间" align="center" prop="clockTime"/>
      <el-table-column label="备注" align="center" prop="clockRemark"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
  // import { exportAttendance, listAttendance } from '@/api/system/attendance'

  export default {
    name: 'Attendance',
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 岗位表格数据
        attendanceList: [],
        dateRange: '',
        // 弹出层标题
        title: '',
        // 是否显示弹出层
        open: false,
        openCharge: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          userName: undefined,
          phoneNumber: undefined,
          clockType: undefined
        },
        // 列信息
        columns: [
          { key: 0, label: `所属运营商`, visible: true },
          { key: 1, label: `姓名`, visible: true },
          { key: 2, label: `手机号`, visible: true },
          { key: 3, label: `打卡类型`, visible: true },
          { key: 4, label: `打卡路段`, visible: true },
          { key: 5, label: `打卡时间`, visible: true },
          { key: 6, label: `备注`, visible: true }
        ],
        formData: {},
        rules: {
          phoneNumber: [{
            pattern: /^1(3|4|5|7|8|9)\d{9}$/,
            message: '手机号格式错误',
            trigger: 'blur'
          }]
        },
        clocktypeOptions: [{
          'label': '上班打卡',
          'value': 0
        }, {
          'label': '下班打卡',
          'value': 1
        }]
      }
    },
    created() {
      this.getList()
    },
    methods: {
      /** 查询考勤列表 */
      getList() {
        this.loading = true
        listAttendance(this.addDateRange1(this.formData, this.dateRange)).then(response => {
            this.attendanceList = response.rows
            this.total = response.total
            this.loading = false
          }
        )
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = []
        this.resetForm('elForm')
        this.handleQuery()
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams
        this.$confirm('是否确认导出所有考勤数据项?', '提示', {
          cancelButtonClass: 'btn-custom-cancel',
          closeOnClickModal: false,
          type: 'info'
        }).then(function() {
          return exportAttendance(queryParams)
        }).then(response => {
          this.download(response.msg)
        })
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.attendanceId)
        this.single = selection.length != 1
        this.multiple = !selection.length
      }
    }
  }

</script>
<style>
</style>
